package com.psjj.mall.controller;

import com.psjj.mall.common.Result;
import com.psjj.mall.exception.MallExceptionEnum;
import com.psjj.mall.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther:云尚学Java
 */
@RestController  //相当与 @Controller+@ResponseBody
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/register")
    public Result register(@RequestParam("userName") String userName,@RequestParam("password")  String password){
        if(!StringUtils.hasText(userName)){
            return Result.error(MallExceptionEnum.NEED_USERNAME);
        }
        if(!StringUtils.hasText(password)){
            return Result.error(MallExceptionEnum.NEED_PASSWORD);
        }
        if(password.length()<6){
            return Result.error(MallExceptionEnum.NEED_PASSWORD_LENGTH);
        }
        userService.register(userName,password);
        return Result.success();
    }

}
